package com.blvtphan.tipocketclubs.abstracts;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;

import com.blvtphan.tipocketclubs.R;
import com.blvtphan.tipocketclubs.custom.CustomTextView;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public abstract class AbstractMapFragment extends FragmentActivity implements FragmentHolderInterface{

	public GoogleMap map;
	public SupportMapFragment mapFragment;
	public Context mContext;
	
	@Override
	protected void onCreate(Bundle bundle) {
		// TODO Auto-generated method stub
		super.onCreate(bundle);
		
		mContext = this;
		
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		
		this.setContentView(getContentViewId());
		
		initCustomTitleBar();
		
		initGoogleMap();
		
		initView();
	}
	
	@Override
	public abstract int getContentViewId();

	@Override
	public abstract void initView();
	
	@Override
	public abstract String getTitleBarTitle();
	
	@Override
	public abstract int getMapViewId();
	
	private void initGoogleMap() {
		Fragment fragment = getSupportFragmentManager().findFragmentById(getMapViewId());
		mapFragment = (SupportMapFragment) fragment;
		map = mapFragment.getMap();
	}
	
	/**
	 * set title for custom title bar
	 */
	private void initCustomTitleBar() {
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_bar);
		CustomTextView tvTitle = (CustomTextView)findViewById(R.id.txt_title_bar);
		tvTitle.setText(getTitleBarTitle());
		ImageView backIcon = (ImageView)findViewById(R.id.btn_back_activity);
		backIcon.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
	}
}
